package com.zillion.employee.service.impl;

import com.zillion.employee.domain.UnitApply;
import com.zillion.employee.domain.UnitPerson;
import com.zillion.employee.mapper.UnitApplyMapper;
import com.zillion.employee.service.IUnitApplyService;
import com.zillion.health.domain.HealthPersonInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UnitApplyServiceImpl implements IUnitApplyService {

    @Autowired
    private UnitApplyMapper unitApplyMapper;

    /**
     * 新增单位申报信息
     *
     * @param unitApplyInfo 单位申报信息
     * @return 处理结果
     */
    @Override
    public int insertUnitApply(UnitApply unitApplyInfo) {
        // 获取单位人员信息集合
        ArrayList<HealthPersonInfo> healthPersonInfos = getHealthPersonInfos(unitApplyInfo);
        return unitApplyMapper.insertUnitApply(healthPersonInfos);
    }

    /**
     * 获取单位人员信息集合
     *
     * @param unitApplyInfo 单位申报信息
     * @return 单位人员信息集合
     */
    private static ArrayList<HealthPersonInfo> getHealthPersonInfos(UnitApply unitApplyInfo) {
        // 创建集合用来装单位人员信息列表
        ArrayList<HealthPersonInfo> healthPersonInfos = new ArrayList<>();

        // 取出单位人员信息集合
        List<UnitPerson> unitPersonList = unitApplyInfo.getUnitPersonList();

        // 对单位人员信息进行处理
        for (UnitPerson unitPerson : unitPersonList) {
            // 创建新的
            HealthPersonInfo healthPersonInfo = new HealthPersonInfo();
            // 单位
            healthPersonInfo.setUnitName(unitApplyInfo.getUnitName());
            healthPersonInfo.setSocialCreditCode(unitApplyInfo.getSocialCreditCode());
            healthPersonInfo.setParkId(unitApplyInfo.getParkId());
            healthPersonInfo.setIsUnit(unitApplyInfo.getIsUnit());
            // 单位人员信息
            healthPersonInfo.setName(unitPerson.getName());
            healthPersonInfo.setIdCard(unitPerson.getIdCard());
            healthPersonInfo.setAge(unitPerson.getAge());
            healthPersonInfo.setGender(unitPerson.getGender());
            healthPersonInfo.setEthnic(unitPerson.getEthnic());
            healthPersonInfo.setEducationLevel(unitPerson.getEducationLevel());
            healthPersonInfo.setWorkYears(unitPerson.getWorkYears());
            healthPersonInfo.setPhone(unitPerson.getPhone());
            healthPersonInfo.setJobTypeId(unitPerson.getJobTypeId());
            healthPersonInfo.setAddress(unitPerson.getAddress());
            // 添加进集合
            healthPersonInfos.add(healthPersonInfo);
        }
        return healthPersonInfos;
    }
}
